﻿using AiXiu.BLL;
using AiXiu.IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AiXiu.WebStite
{
    /// <summary>
    /// VideoLikeHandler 的摘要说明
    /// </summary>
    public class VideoLikeHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //接收参数
            string videoId = context.Request.QueryString["videoId"];
            string userIdStr = context.Request.QueryString["userId"];
            if (!string.IsNullOrWhiteSpace(userIdStr) && !string.IsNullOrWhiteSpace(videoId))
            {
                //执行操作
                int userId = int.Parse(userIdStr);
                ILikeManager likeManager = new LikeManager();
                if (likeManager.IsLike(videoId, userId))
                {
                    likeManager.RemoveLike(videoId, userId);
                }
                else
                {
                    likeManager.AddLike(videoId, userId);

                }
                //输出结果
                context.Response.ContentType = "text/plain";
                context.Response.Write("OK");
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}